﻿using MongoDB.Bson;
using MongoDB.Driver.GridFS;
using Ongoal.Quotation.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ongoal.Quotation.Service.Interface
{
    /// <summary>
    /// MongoDB文件操作相关接口
    /// </summary>
    public interface IMongoFileRepo : IServiceBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        ObjectId GetInternalId(string id);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSFileInfo> GetFileById(string id, string bucketName = "");
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSFileInfo> GetFileById(ObjectId id, string bucketName = "");
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        Task<GridFSFileInfo> FindFileByFileName(string filename);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="source"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<ObjectId> UploadFile(string fileName, Stream source, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSDownloadStream<ObjectId>> DownloadFileStreamSeekable(string id, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSDownloadStream<ObjectId>> DownloadFileStreamSeekable(ObjectId id, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSDownloadStream<ObjectId>> DownloadFileStream(string id, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="outfile"></param>
        /// <param name="bucketName"></param>
        void DownloadToStream(ObjectId id, FileStream outfile, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task<GridFSDownloadStream<ObjectId>> DownloadFileStream(ObjectId id, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task DeleteFile(string id, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task DeleteFile(ObjectId id, string bucketName = "");


        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newFilename"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task RenameFile(string id, string newFilename, string bucketName = "");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newFilename"></param>
        /// <param name="bucketName"></param>
        /// <returns></returns>
        Task RenameFile(ObjectId id, string newFilename, string bucketName = "");
    }
}
